<?php

namespace app\utils;

use think\facade\Cache;

/**
 * 单例模式测试
 * Class Demo
 * @package projects\utils
 * User：DU
 * Date: 2021/7/1
 * Time: 11:13
 */
class Demo
{
    protected static $instance;

    public $int;

    private function __construct()
    {
        $this->int = mt_rand(111, 999);
    }

    private function __clone()
    {
    }

    public static function getInstance()
    {
        if (is_null(self::$instance) && !Cache::get('demo')){
            self::$instance = new Demo();

        }

        return self::$instance;
    }
}
